from langchain_community.chat_models import ChatTongyi
from langchain.prompts import ChatPromptTemplate
import os

from langchain_core.messages import SystemMessage, HumanMessage

os.environ["DASHSCOPE_API_KEY"] = "sk-9d8f1914800e497f8717144e860f99bc"
llm = ChatTongyi()

template = ChatPromptTemplate.from_messages(
    [
        SystemMessage(
            content=(
                "你是一个乐于助人的助手，可以将用户的文本重新写入"
                "听起来更乐观"
                "用中文回复我"
            )
        ),
        # HumanMessagePromptTemplate.from_template("{text}"), # 这里对应本小节前面，所示的from_template可以从已有模板进行修改
        HumanMessage(
            content=(
                "{text}"
            )
        ),
    ]
)
messages = template.format_messages(text="我现在很焦虑")

res = llm.invoke(messages)
print(res)
